﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Report.cs" company="Spenta Consulting">
//   (c) Copyright 2011
// </copyright>
// <summary>
//   Complements the Report class with extra information
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Spenta.StreetCare.Core.Models
{
    using System.ComponentModel.DataAnnotations;
    using System.Linq;

    using Spenta.StreetCare.Core.Attributes;
    using Spenta.StreetCare.Core.Shared.Attributes;

    /// <summary>
    /// Complements the Report class with extra information
    /// </summary>
    [MetadataType(typeof(ReportMetadata))]
    public partial class Report
    {
        /// <summary>
        /// Gets the report rating.
        /// </summary>
        public double ReportRating
        {
            get
            {
                return this.Comments.Count == 0 ? 0 : this.Comments.Average(c => c.CommentRating);
            }
        }

        /// <summary>
        /// Metadata for Report class
        /// </summary>
        public class ReportMetadata
        {
            /// <summary>
            /// Gets or sets the report title.
            /// </summary>
            /// <value>
            /// The report title.
            /// </value>
            [LocalizedRequired("ReportTitleRequired")]
            [LocalizedStringLength(255)]
            [LocalizedDisplayName("ReportTitleField")]
            public string ReportTitle { get; set; }

            /// <summary>
            /// Gets or sets the report location.
            /// </summary>
            /// <value>
            /// The report location.
            /// </value>
            [LocalizedRequired("ReportLocationRequired")]
            [LocalizedStringLength(255)]
            [LocalizedDisplayName("ReportLocationField")]
            public string ReportLocation { get; set; }

            /// <summary>
            /// Gets or sets the report notification details.
            /// </summary>
            /// <value>
            /// The report notification details.
            /// </value>
            [LocalizedRequired("ReportNotificationDetailsRequired")]
            [LocalizedStringLength(2000)]
            [LocalizedDisplayName("ReportNotificationDetailsField")]
            public string ReportNotificationDetails { get; set; }

            /// <summary>
            /// Gets or sets the report latitude.
            /// </summary>
            /// <value>
            /// The report latitude.
            /// </value>
            [LocalizedRange(-90, 90)]
            [LocalizedDisplayName("ReportLatitudeField")]
            public double ReportLatitude { get; set; }

            /// <summary>
            /// Gets or sets the report longitude.
            /// </summary>
            /// <value>
            /// The report longitude.
            /// </value>
            [LocalizedRange(-90, 90)]
            [LocalizedDisplayName("ReportLongitudeField")]
            public double ReportLongitude { get; set; }

            /// <summary>
            /// Gets or sets the report notification type ID.
            /// </summary>
            /// <value>The report notification type ID.</value>
            [LocalizedRange(1, 2)]
            [LocalizedDisplayName("ReportNotificationIDField")]
            public int ReportNotificationTypeID { get; set; }
        }
    }
}
 
